﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QuickApp.MVCControl.FlexiGrid
{
    /// <summary>
    /// 表格的列信息
    /// </summary>
    public class FlexiGridColumn
    {
        public FlexiGridColumn(string fieldName)
        {
            this.ColumnSettings = new FlexiGridColumnSettings();
            this.FieldName = fieldName;
        }

        /// <summary>
        /// 字段名称
        /// </summary>
        public string FieldName { get; private set; }

        /// <summary>
        /// 列配置信息
        /// </summary>
        public FlexiGridColumnSettings ColumnSettings { get; private set; }

        #region 枚举列的帮助方法
        /// <summary>
        /// 判断列名称是否为枚举列
        /// </summary>
        /// <param name="columnName"></param>
        /// <returns></returns>
        public static bool IsEnumColumn(string columnName)
        {
            return columnName.IndexOf(DWZSysConstant.FLEXIGRID_COLUMN_ENUM_KEY_SEPARATOR) > 0;
        }

        /// <summary>
        /// 获取枚举列的枚举项值的字段名称·
        /// </summary>
        /// <param name="columnName"></param>
        /// <returns></returns>
        public static string GetEnumColumnField(string columnName)
        {
            if (IsEnumColumn(columnName))
            {
                return columnName.Split(DWZSysConstant.FLEXIGRID_COLUMN_ENUM_KEY_SEPARATOR.ToCharArray())[0];
            }
            return columnName;
        }

        /// <summary>
        /// 获取枚举列的枚举项的Key值
        /// </summary>
        /// <param name="columnName"></param>
        /// <returns></returns>
        public static string GetEnumColumnKey(string columnName)
        {
            if (IsEnumColumn(columnName))
            {
                return columnName.Split(DWZSysConstant.FLEXIGRID_COLUMN_ENUM_KEY_SEPARATOR.ToCharArray())[1];
            }
            return string.Empty;
        }
        #endregion
    }
}
